The London Eye Credit…John Harper/Spaces Images, via Corbis
Cloudflare Workers is a serverless platform for creating entirely new applications or augmenting existing ones without configuring or maintaining infrastructure. To enable the KV store required to serve the Gatsby files, you’ll need the Workers Unlimited plan for $5/month.
Gatsby is a React-based open-source framework for creating websites and apps. Build anything you can imagine with over 2000 plugins and performance, scalability, and security built-in by default.
Note: I don’t think it’s fair to call Gatsby a static site generator, because it’s much more than that. If you haven’t heard of Gatsby before, definitely go check it out.
Wrangler is a CLI (Command Line Interface) tool designed for folks who are interested in using and managing Cloudflare Workers projects. * Use wrangler to deploy your Gatsby application globally without leaving the command-line interface.
Cloud Build is a service that executes your builds on Google Cloud Platform infrastructure. Cloud Build can import source code from Google Cloud Storage, Cloud Source Repositories, GitHub, or Bitbucket, execute a build to your specifications, and produce artifacts such as Docker containers or Java archives.
Configure wrangler.toml. First, add account ID field and then either
npm install -g gatsby-cli
Open site directory in vscode
git add .
git commit -m “initial commit
git remote add origin gitrepolink\
git push -u origin master
Start the development server —>gatsby develop
Now gatsby will start a hot-reloading development environment accessible by default at http://localhost:8000. Try editing the home page in src/pages/index.js. Saved changes will live to reload in the browser.
Gatsby starts a local HTML server for testing your built site. Remember to build your site using gatsby build before using this command.
wrangler subdomain
If you encountered below error after wrangler publish don’t panic
Select one of the following options based on your business need:
Check the consent checkbox and click Next. In the Select repository page that appears, connect your GitHub repositories to your Cloud project as follows:
a. Confirm the correct GitHub account has been selected. b. Select the checkbox next to each target repository. c. Read the consent disclaimer and select the checkbox next to it to indicate that you accept the presented terms. d. Click Connect repository.
If you don’t see one or more of your target repositories, click Edit repositories on GitHub and repeat the steps above to enable additional repositories in the Cloud Build app.
Note:Add substitutions variables directly in cloudbuild while adding repository
steps:
# Install dependencies
- name: node:10.16.0
id: Installing dependencies...
entrypoint: npm
args: ["install"]
waitFor: ["-"] # Begin immediately
# Gatsby build
- name: node:10.16.0
id: Building Gatsby site...
entrypoint: npm
args: ["run", "build"]
# Wrangler
- name: 'node'
args: ['bash', '-c', 'npm i @cloudflare/wrangler && ./node_modules/.bin/wrangler publish']
env:
- 'CF_API_TOKEN=${_CF_API_TOKEN}'
- 'CF_ACCOUNT_ID=${_CF_ACCOUNT_ID}'
- 'USER=root'